#!/bin/bash

if [ $# -lt 1 ]; then
   echo "Usage: $0 <app name>"
   exit 1
fi

n=$1
shift

cmd=$@

id=$(docker ps | awk '/'"$n"'/ && $3 !~ "/pause" {print $1}')

if [ -z "$cmd" ]; then
 echo $id
 exit 0
fi

pid=$(docker inspect -f '{{.State.Pid}}' $id)

nsenter -t $pid -n $cmd
